//
//  FrienddynamicViewController.m
//  CheekiOS
//
//  Created by mac on 2017/6/1.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "FrienddynamicViewController.h"

@interface FrienddynamicViewController ()

@property (nonatomic, strong) UIImageView *imgView;


@end

@implementation FrienddynamicViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    _imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Friend_illustrations"]];
    
    _imgView.frame = CGRectMake(38, 64+11, KScreenWidth-76, 399);
    _imgView.userInteractionEnabled = YES;
    [self.view addSubview:_imgView];

    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button addTarget:self action:@selector(buttonClickDisMiss) forControlEvents:UIControlEventTouchUpInside];
    button.frame = CGRectMake(_imgView.right-38-27, _imgView.top-22, 25, 25);
    [button setImage:[UIImage imageNamed:@"Friend_news_cancel"] forState:UIControlStateNormal];
    [_imgView addSubview:button];
    
    
    
    
    UILabel *lab = [[UILabel alloc] initWithFrame:CGRectMake(0, _imgView.height/2, _imgView.width, 30)];
    lab.text = @"发布动态";
    lab.font = FontP(16);
    lab.textAlignment = NSTextAlignmentCenter;
    [_imgView addSubview:lab];
    
    NSArray *arr = @[@"文字",@"图片",@"拍照",@"视频"];
    
    CGFloat btnK = 15;
    CGFloat btnW = (_imgView.width - 60)/4;
    
    for (int i = 0; i < arr.count ; i++) {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.frame = CGRectMake(btnK+(i*(btnK+btnW-5)), lab.bottom+45, btnW, btnW);
        
        btn.tag = i;
        if (i == 0) {
            [btn setBackgroundImage:[UIImage imageNamed:@"Friend_news_words"] forState:UIControlStateNormal];
        }else if (i == 1){
            [btn setBackgroundImage:[UIImage imageNamed:@"Friend_news_picture"] forState:UIControlStateNormal];

        }else if (i == 2){
            [btn setBackgroundImage:[UIImage imageNamed:@"Friend_news_photograph"] forState:UIControlStateNormal];

        }else{
            [btn setBackgroundImage:[UIImage imageNamed:@"Friend_news_video"] forState:UIControlStateNormal];

        }
        [btn addTarget:self action:@selector(btnClickdynamic:) forControlEvents:UIControlEventTouchUpInside];
        UILabel *lab = [[UILabel alloc] init];
        lab.frame =CGRectMake(btnK+(i*(btnK+btnW-5)), btn.bottom, btnW, 20);
        lab.text = arr[i];
        lab.font = FontP(12);
        lab.textAlignment = NSTextAlignmentCenter;
        lab.textColor = ColorI(0x2e353f);
        [_imgView addSubview:btn];
        [_imgView addSubview:lab];
    }
    
    [self.view addSubview:_imgView];
    
    
    
}

- (void)btnClickdynamic:(UIButton *)btn{
    [self buttonClickDisMiss];
    if ([self.delegate respondsToSelector:@selector(didClickButtonFrienddynamic:)]) {
        [self.delegate didClickButtonFrienddynamic:btn.tag];
    }

}

- (void)buttonClickDisMiss{
    CATransition * animation = [CATransition animation];
    
    animation.duration = 0.5;    //  时间
    
    /**  type：动画类型
     *  pageCurl       向上翻一页
     *  pageUnCurl     向下翻一页
     *  rippleEffect   水滴
     *  suckEffect     收缩
     *  cube           方块
     *  oglFlip        上下翻转
     */
    //    animation.type = @"pageCurl";
    
    /**  type：页面转换类型
     *  kCATransitionFade       淡出
     *  kCATransitionMoveIn     覆盖
     *  kCATransitionReveal     底部显示
     *  kCATransitionPush       推出
     */
    animation.type = kCATransitionFade;
    
    //PS：type 更多效果请 搜索： CATransition
    
    /**  subtype：出现的方向
     *  kCATransitionFromRight       右
     *  kCATransitionFromLeft        左
     *  kCATransitionFromTop         上
     *  kCATransitionFromBottom      下
     */
    
    
    [self.view.window.layer addAnimation:animation forKey:nil];
    [self dismissViewControllerAnimated:NO completion:nil];

}

@end
